<?php if(! defined("BASEPATH")) exit("No direct access allowed!");
	
class Admin_model extends CI_Model {
	private $admininfodb = "admin";

	function __construct()
	{
		$this->load->database();
	}

	/* 管理员的登陆身份校验函数 */
	public function admin_login_validation($formdata)
	{
		$this->db->select('id');
		$this->db->from("admin");
		$this->db->where('name'	,	$formdata['name']);
		$this->db->where('pwd'	,	$formdata['pwd']);
		$query = $this->db->get();
		if(count($query->row_array()) !== 1)
			return false;
		else
			return true;
	}

	// 使用获取指定的管理员信息，由admin_id指定或者username指定
	public function get_admininfo($key, $value)
	{
		if(in_array($key, array("admin_id", "username")))
		{
			return false;
		}
		return $this->db->from($this->admininfodb)
			->select("*")
			->where($key, $value)
			->get()
			->row_array();
	}


	/* 检查该管理员是否存在，存在，则返回true，不存在，则返回false */
	public function check_admin_exist($condition)
	{
		$query = $this->db->from($this->admininfodb)
			->select('*')
			->where($condition)
			->get();
		if(count($query->row_array()) == 0)
			return false;
		else
			return true;
	}

	public function add_admin($adminform)
	{
		return $this->db->insert($this->admininfodb, $adminform);
	}

	// 获取管理员信息列表
	public function get_admin_list($limit, $offset = 0)
	{
		$result = $this->db->from($this->admininfodb)
			->order_by("admin_id", "desc")
			->limit($limit, $offset)
			->get()
			->result_array();
		return $result;
	}
}

?>
